
package com.gene.controller;

import com.gene.pojo.UpmsUser;
import com.gene.pojo.UserGeneticcurrency;
import com.gene.service.IUserGeneticcurrencyService;
import com.gene.utils.ResultData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;



/**
 * 用户基因币账单详情
 */
@Controller
@RequestMapping("/gene-safe/userGeneticcurrency")
public class UserGeneticcurrencyController {
    @Autowired
    private IUserGeneticcurrencyService userGeneticcurrencyService;



/**
     * 查询    userId为查询条件
     * @param userGeneticcurrency
     * @return
     */
    @RequestMapping(value="/query")
    @ResponseBody
    public ResultData query(UserGeneticcurrency userGeneticcurrency){
        ResultData result=new ResultData();
        List<UserGeneticcurrency> list=userGeneticcurrencyService.query(userGeneticcurrency);
        if(list.size()>0){
            result.setData(list);
            result.setStatus("1");
            result.setMsg("查询成功！");
        }else{
            result.setStatus("0");
            result.setMsg("没有数据！");
        }

        return result;
    }



/**
     * 新增
     * @param userGeneticcurrency
     * @return
     */
    @RequestMapping(value="/add")
    @ResponseBody
    public ResultData add(UserGeneticcurrency userGeneticcurrency){
        ResultData result =new ResultData();
        boolean a=userGeneticcurrencyService.add(userGeneticcurrency);
        if(a){
            result.setStatus("1");
            result.setMsg("新增成功...");
        }else{
            result.setStatus("0");
            result.setMsg("新增失败！");
        }
        return result;
    }


/**
     * 修改
     *
     * @param userGeneticcurrency
     * @return
     */
    @RequestMapping(value="/edit")
    @ResponseBody
    public ResultData edit(UserGeneticcurrency userGeneticcurrency){
        ResultData result =new ResultData();
        boolean a=userGeneticcurrencyService.edit(userGeneticcurrency);
        if(a){
            result.setStatus("1");
            result.setMsg("修改成功...");
        }else{
            result.setStatus("0");
            result.setMsg("修改失败！");
        }
        return result;
    }


/**
     * 删除
     * @param userGeneticcurrency
     * @return
     */
    @RequestMapping(value="/delete")
    @ResponseBody
    public ResultData delete(UserGeneticcurrency userGeneticcurrency) {
        ResultData result = new ResultData();
        boolean a=userGeneticcurrencyService.delete(userGeneticcurrency);
        if(a){
            result.setStatus("1");
            result.setMsg("删除成功...");
        }else{
            result.setStatus("0");
            result.setMsg("删除失败！");
        }
        return result;
    }


    /**
     * 根据userId查询基因币总和
     */
    @RequestMapping(value="/sum")
    @ResponseBody
    public ResultData sum(UserGeneticcurrency userGeneticcurrency) {
        ResultData result = new ResultData();
        Long sum = userGeneticcurrencyService.sum(userGeneticcurrency);
        if(null == sum) sum = Long.valueOf(0);
        result.setData(sum);
        result.setStatus("1");
        result.setMsg("查询成功...");

        return result;
    }


    /**
     * 根据用户名查询出该用户是否存在
     */
    @RequestMapping(value="/queryUsername")
    @ResponseBody
    public ResultData queryUsername(String username) {
        ResultData result = new ResultData();
        UpmsUser upmsUser = userGeneticcurrencyService.queryUsername(username);

        if(null != upmsUser){
            result.setData(upmsUser);
            result.setStatus("1");
            result.setMsg("正确");
        }else{
            result.setStatus("0");
            result.setMsg("用户不存在");
        }

        return result;
    }


    /**
     * 基因币转赠接口
     */
    @RequestMapping(value="/present")
    @ResponseBody
    public ResultData present(UserGeneticcurrency userGeneticcurrency) {
        ResultData result = new ResultData();
        boolean b = userGeneticcurrencyService.present(userGeneticcurrency);

        if(b){

            result.setStatus("1");
            result.setMsg("转赠成功");
        }else{
            result.setStatus("0");
            result.setMsg("转赠失败");
        }

        return result;
    }
}


